# run_tests.py
#!/usr/bin/env python3
"""
测试运行脚本
"""
import subprocess
import sys

def run_tests():
    """运行所有测试"""
    # 运行单元测试
    print("运行单元测试...")
    result = subprocess.run([
        sys.executable, "-m", "pytest", 
        "tests/test_units", 
        "-v", 
        "--tb=short"
    ])
    
    if result.returncode != 0:
        print("单元测试失败!")
        return result.returncode
    
    # 运行模拟测试
    print("\n运行模拟测试...")
    result = subprocess.run([
        sys.executable, "-m", "pytest", 
        "tests/test_mocks", 
        "-v", 
        "--tb=short"
    ])
    
    if result.returncode != 0:
        print("模拟测试失败!")
        return result.returncode
    
    # 运行集成测试
    print("\n运行集成测试...")
    result = subprocess.run([
        sys.executable, "-m", "pytest", 
        "tests/test_integration", 
        "-v", 
        "--tb=short"
    ])
    
    if result.returncode != 0:
        print("集成测试失败!")
        return result.returncode
    
    print("\n所有测试通过!")
    return 0

if __name__ == "__main__":
    sys.exit(run_tests())